<?php
/**
 *程序的根目录
 */
date_default_timezone_set('Asia/Shanghai');
define('__ROOT',realpath(dirname(__FILE__)).'/');
include __ROOT.'libs/Application.php';
include __ROOT.'libs/db/ez_sql_core.php';
include __ROOT.'libs/db/ez_sql_mysql.php';
include __ROOT.'libs/function.php';
include __ROOT.'libs/Out.php';
include __ROOT.'libs/Mail.php';
include __ROOT.'libs/Debug.php';
include __ROOT.'config/Error.php';
/**
 * ulr的格式 /app/control/action/type/callback
 *          /应用名字/控制器/接口名字/返回数据类型/jsonp格式的回调函数
 */
urlRedirect();//要是使用的有重定向的话就做一下处理
$app = get('_app_');
$control = get('_m_');
$action = get('_c_');
getApp($app)->run($control,$action);

function urlRedirect(){
    $info = pathinfo($_SERVER['REQUEST_URI']);
    $fname = pathinfo(__FILE__);
    if($info['filename'] != $fname['filename']){
        //这是重定向过来的
        $app = pathinfo($_SERVER["PHP_SELF"]);
        $url = $_SERVER['REQUEST_URI'];
        if(empty($app)){
            $app = '';
        }elseif($app['dirname'] == '/'){
            $app = '';
        }
        if($app){
            $url = str_replace($app.'/', '',$url );
        }elseif(strpos($url, '/') === 0){
            $url = substr($url,1);
        }
        $url = strtolower($url);
        $list = explode('/', $url);
        if($list){
            $_GET['_app_'] = isset($list[0]) ? $list[0] : '';
            $_GET['_m_'] = isset($list[1]) ? $list[1] : '';
            $_GET['_c_'] = isset($list[2]) ? $list[2] : '';
            $_GET['_t_'] = isset($list[3]) ? $list[3] : '';
            $_GET['_callback_'] = isset($list[4]) ? $list[4] : '';
        }
    }
}


